package com.lilihub.miaosha.intercepter;

import com.lilihub.miaosha.domain.MiaoshaUser;

/**
 * @BelongsProject: miaosha
 * @BelongsPackage: com.lilihub.miaosha.intercepter
 * @Author: LiYing
 * @CreateTime: 2021-04-30 15:09
 * @Description:
 */
public class UserContext {

    /**
     * ThreadLocal与当前线程绑定，放的user对象是当前线程的user对象
     * 即使是多线程访问，也不存在线程安全问题
     */
    private static ThreadLocal<MiaoshaUser> userHolder = new ThreadLocal<>();


    public static void setUser(MiaoshaUser user){

        userHolder.set(user);
    }

    public static MiaoshaUser getUser(){

       return userHolder.get();
    }


}
